package lab03.test07;

import java.io.*;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

public class Test07 {
    public static void main(String[] args) {


        ZipFile zipFile = null;

        String path = "E:\\book.zip";
        try {
            zipFile = new ZipFile(path);

            Enumeration entries = zipFile.entries();
            ZipEntry zipEntry = null;
            while (entries.hasMoreElements()) {

                zipEntry = (ZipEntry) entries.nextElement();

                //创建test文件夹
                File testFile = new File("E:\\test\\123");
                testFile.mkdir();

                //字节流 读文件 写文件
                InputStream fileInputStream = zipFile.getInputStream(zipEntry);
                FileOutputStream fileOutputStream = new FileOutputStream(
                        new File("E:\\test\\" + zipEntry.getName())
                );
                byte[] data = new byte[1024];
                while ((fileInputStream.read(data)) != -1) {

                    fileOutputStream.write(data);
                }
                fileInputStream.close();
                fileOutputStream.close();

            }


        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                zipFile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
}
